package org.hzandyy.framework.liteflow.flow;

import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.math.RandomUtils;

import java.util.List;

/**
 * @author Hu Zhi
 * @since 2023/12/7 15:50
 */
@LiteflowComponent("node_switch")
@Slf4j
public class NodeSwitchCmp extends NodeSwitchComponent {

    @Override
    public String processSwitch() throws Exception {
        var nodes = List.of(
            "a", // 选择targetId是a的节点
            "a:", // 选择第一个targetId是a的节点
            "w1", // 通过id 批量选择节点
            "e:td", // 选择targetId是e且标签为td的节点
            "tag:td", ":td", // 需要lite-flow>v2.9.0, 选择第一个标签为td的节点
            ":", // 选择第一个节点
            ":chain"
        );
        String node = nodes.get(RandomUtils.nextInt() % nodes.size());
        log.info("random switch node [{}]", node);
        return node;
    }

}
